home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / SSN.java < prev    next >
Text File  |  1998-11-01  |  821b  |  49 lines

  1. /**
  2.  * An employee social-security number object. Allows creation, validation, and
  3.  * ordering of employee SS #'s.
  4.  */
  5.  
  6. public class SSN
  7. {
  8.     String val;
  9.     final static int MAX_LENGTH = 11;
  10.  
  11.     SSN(String s)
  12.     {
  13.         val = s;
  14.             //{{INIT_CONTROLS
  15.         //}}
  16. }
  17.  
  18.     String value()
  19.     {
  20.         return val;
  21.     }
  22.  
  23.     public boolean isValid()
  24.     {
  25.         if (val.length() > MAX_LENGTH) return false;
  26.         if (val.charAt(3) != '-') return false;
  27.         if (val.charAt(6) != '-') return false;
  28.         try
  29.         {
  30.             Integer.parseInt(val.substring(0, 2));
  31.             Integer.parseInt(val.substring(4, 5));
  32.             Integer.parseInt(val.substring(7, 10));
  33.         }
  34.         catch (NumberFormatException e)
  35.         {
  36.             return false;
  37.         }
  38.         return true;
  39.     }
  40.  
  41.     public boolean isGreaterThan(SSN s)
  42.     {
  43.         return val.compareTo(s.val) > 0;
  44.     }
  45.     //{{DECLARE_CONTROLS
  46.     //}}
  47. }
  48.  
  49.